package com.bsi.login.oauth.config;


import com.bsi.login.oauth.entity.OauthVisitModeEnum;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.Map;
import java.util.Objects;

/*
 * Author: liusongs
 * Date: 2019/10/18 10:45
 * Content: 连接auth服务所需要的客户端令牌和token请求地址
 */
@Configuration
@ConfigurationProperties(prefix = "oauth")
@RefreshScope
public class OauthFieldProperties {

    private String serviceId;  // auth服务id

    private String tokenUriInfo;     // auth服务获取token地址

    private String clientId; // 在oauth2数据库中配置客户端id

    private String clientSecret; // 在oauth2数据库中配置客户端秘钥

    private String grant_type = "password";// oauth的模式("设置默认为密码模式") 当需要刷新token时将grant_type改成refresh_token模式

    private final String oauthHead = "Authorization";// 访问oauth时需要带上此值作为请求头key值

    public String getOauthHead() {
        return oauthHead;
    }

    public String getGrant_type() {
        return grant_type;
    }

    public void setGrant_type(String grant_type) {
        this.grant_type = grant_type;
    }

    public String getTokenUriInfo() {
        return tokenUriInfo;
    }

    public void setTokenUriInfo(String tokenUriInfo) {
        this.tokenUriInfo = tokenUriInfo;
    }

    public String getClientId() {
        return clientId;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public String getClientSecret() {
        return clientSecret;
    }

    public void setClientSecret(String clientSecret) {
        this.clientSecret = clientSecret;
    }

    public String getServiceId() {
        return serviceId;
    }

    public void setServiceId(String serviceId) {
        this.serviceId = serviceId;
    }

    public OauthFieldProperties() {
    }

    public OauthFieldProperties(String serviceId, String tokenUriInfo, String clientId, String clientSecret, String grant_type) {
        this.serviceId = serviceId;
        this.tokenUriInfo = tokenUriInfo;
        this.clientId = clientId;
        this.clientSecret = clientSecret;
        this.grant_type = grant_type;
    }


    /**
     * @param oauthVisitModeEnum 选择模式
     * @return OauthFieldProperties
     */
    public OauthFieldProperties selectTokenMode(OauthVisitModeEnum oauthVisitModeEnum) {
        return new OauthFieldProperties(serviceId, oauthVisitModeEnum.getTokenUriInfo(), clientId, clientSecret, oauthVisitModeEnum.getGrantType());
    }


}
